package org.gege.com.controller;

import java.util.ArrayList;

import org.gege.crawler.AutoHome;
import org.gege.crawler.ListItem;
import org.gege.crawler.NewsItem;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import scala.collection.immutable.List;
@EnableAutoConfiguration
@RestController
@RequestMapping("/user")
public class TestController {
    
    @RequestMapping("/{id}")  
    public java.util.List<NewsItem> view(@PathVariable("id") Long id) {  
        
        java.util.List<NewsItem> list = new ArrayList<NewsItem>();
        
        AutoHome autoHome = new AutoHome();
        
        try {
            for(int i = 1; i <= 10; i ++) {
                List<ListItem> itemList = autoHome.itemList(i);
                
                if(itemList != null) {
                    for(int index = 0; index < itemList.size(); index ++) {
                        ListItem item = itemList.apply(index);
                        if(item != null) {
                            list.add(item.toNewsItem());
                        }
                    }
                }
            }
            return list;
        } catch (Exception e) {
            e.printStackTrace();
        } 
        return list;  
    }  
}
